package com.mars.module.admin.controller;


import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import com.mars.common.enums.BusinessType;
import com.mars.common.result.R;
import com.mars.common.util.ExcelUtils;
import io.swagger.annotations.Api;
import com.mars.framework.annotation.RateLimiter;
import com.mars.module.admin.entity.SysUserLikeComment;
import com.mars.framework.annotation.Log;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import com.mars.common.response.PageInfo;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import com.mars.module.admin.service.ISysUserLikeCommentService;
import com.mars.module.admin.request.SysUserLikeCommentRequest;

import javax.servlet.http.HttpServletResponse;

/**
 * 点赞评论控制层
 *
 * @author mars
 * @date 2024-03-24
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "7.点赞评论接口管理",tags = "7.点赞评论接口管理")
@RequestMapping("/admin/sysUserLikeComment" )
public class SysUserLikeCommentController {

    private final ISysUserLikeCommentService iSysUserLikeCommentService;

    /**
     * 分页查询点赞评论列表
     */
    @ApiOperation(value = "分页查询点赞评论列表")
    @PostMapping("/pageList")
    public R<PageInfo<SysUserLikeComment>> pageList(@RequestBody SysUserLikeCommentRequest sysUserLikeCommentRequest) {
        return R.success(iSysUserLikeCommentService.pageList(sysUserLikeCommentRequest));
    }

    /**
     * 获取点赞评论详细信息
     */
    @ApiOperation(value = "获取点赞评论详细信息")
    @GetMapping(value = "/query/{id}")
    public R<SysUserLikeComment> detail(@PathVariable("id") Long id) {
        return R.success(iSysUserLikeCommentService.getById(id));
    }

    /**
     * 新增点赞评论
     */
    @Log(title = "新增点赞评论", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增点赞评论")
    @PostMapping("/add")
    public R<Void> add(@RequestBody SysUserLikeCommentRequest sysUserLikeCommentRequest) {
        iSysUserLikeCommentService.add(sysUserLikeCommentRequest);
        return R.success();
    }

    /**
     * 修改点赞评论
     */
    @Log(title = "修改点赞评论", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改点赞评论")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody SysUserLikeCommentRequest sysUserLikeCommentRequest) {
        iSysUserLikeCommentService.update(sysUserLikeCommentRequest);
        return R.success();
    }

    /**
     * 删除点赞评论
     */
   /* @Log(title = "删除点赞评论", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除点赞评论")
    @PostMapping("/delete/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        iSysUserLikeCommentService.deleteBatch(Arrays.asList(ids));
        return R.success();
    }*/
    @Log(title = "删除点赞评论", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除点赞评论")
    @PostMapping("/delete")
    public R<Void> remove(@RequestParam(value = "id") String id) {
        iSysUserLikeCommentService.deleteByCommentId(id);
        return R.success();
    }
    /**
    * 导出点赞评论
    *
    * @param response response
    * @throws IOException IOException
    */
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response,@RequestBody SysUserLikeCommentRequest sysUserLikeCommentRequest) throws IOException {
        List<SysUserLikeComment> list = iSysUserLikeCommentService.list(sysUserLikeCommentRequest);
        ExcelUtils.exportExcel(list, SysUserLikeComment.class, "点赞评论信息", response);
    }
}
